<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	function myFlat(arr,num){
		if(num <= 0){
			return [...arr]
		}
		let result = []
		arr.forEach(item => {
			if (Array.isArray(item)){
				result.push(...myFlat(item,num - 1))
			} else {
				result.push(item)
			}
		})
		return result
	}
	
	console.log(myFlat([1,2,3,[4,5],6,[7,[8,9]]],2))
</script>
</html>